// Code scaffolded by goctl. Safe to edit.
// goctl 1.9.1

package menu

import (
	"audio-server/internal/model"
	"context"
	"database/sql"

	"audio-server/internal/svc"
	"audio-server/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type MenuSaveLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewMenuSaveLogic(ctx context.Context, svcCtx *svc.ServiceContext) *MenuSaveLogic {
	return &MenuSaveLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *MenuSaveLogic) MenuSave(req *types.MenuSaveReq) (resp *types.BaseMsgResp, err error) {
	menuModel := model.NewMenuModel(l.svcCtx.Conn)

	menu := &model.Menu{
		ParentId:  sql.NullInt64{Int64: int64(req.ParentId), Valid: true},
		Title:     sql.NullString{String: req.Title, Valid: true},
		Path:      req.Path,
		Component: req.Component,
		Redirect:  sql.NullString{String: req.Redirect, Valid: true},
		Type:      sql.NullInt64{Int64: int64(req.Type), Valid: true},
		SvgIcon:   sql.NullString{String: req.SvgIcon, Valid: true},
		Icon:      sql.NullString{String: req.Icon, Valid: true},
		KeepAlive: int64(req.KeepAlive),
		Hidden:    sql.NullInt64{Int64: int64(req.Hidden), Valid: true},
		// 其他字段根据需要设置默认值
	}
	_, err = menuModel.Insert(l.ctx, menu)
	if err != nil {
		return nil, err
	}
	return nil, nil
}
